package com.team.RunsFast_Api.controller;



import com.team.RunsFast_Api.config.SystemConfig;
import com.team.RunsFast_Api.dto.PositionDto;
import com.team.RunsFast_Api.dto.StoreAddDto;
import com.team.RunsFast_Api.dto.StoreQueryDto;
import com.team.RunsFast_Api.service.impl.StoreServiceImpl;
import com.team.RunsFast_Api.service.intf.StoreService;
import com.team.runsfast.entity.Store;
import com.team.runsfast.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;

/**
 * @author fxy
 * @date 2022/9/15
 */
@RestController
@RequestMapping("/api/store/")
@Api(tags = "商铺操作")
@CrossOrigin
public class StoreController {

    private StoreServiceImpl service;

    public StoreController(StoreServiceImpl service) {
        this.service = service;
    }

    //添加一条商铺信息  34.75343885
    //  113.63141921
    @PostMapping("addstore.do")
    @ApiOperation(value = "添加一条商铺信息")
    public R addStore( @RequestBody StoreAddDto store,  String lat,String lng){
        return service.addStore(store,lat,lng);
    }

    //查询位置范围内的商铺信息
    @PostMapping("selectstore.do")
    @ApiOperation(value = "查询商铺信息")
    public R selectStore(String lats,String lngs,HttpServletRequest request){
        return service.selectByUserPos(lats,lngs,request.getHeader(SystemConfig.HEADER_TOKEN));
    }

    //根据餐品类型查询位置范围内的商铺信息
    @PostMapping("selectbytype.do")
    @ApiOperation(value = "类型查询商铺信息")
    public R selectType(@RequestBody StoreQueryDto storeQueryDto,HttpServletRequest request){
        return service.selectByType(request.getHeader(SystemConfig.HEADER_TOKEN),storeQueryDto);
    }



    //查询指定的商铺信息
    @GetMapping("selectbyid.do")
    @ApiOperation(value = "查询指定商铺信息")
    public R selectbyid(Long id){
        return service.selectById(id);
    }


    //评分
    @GetMapping("orderBycomment.do")
    @ApiOperation(value = "查询指定商铺信息")
    public R orderByComment(String lngs,String lats,HttpServletRequest request){
        return service.selectByComments(lats,lngs,request.getHeader(SystemConfig.HEADER_TOKEN));
    }

}
